package cn.david.org.service.impl;

import cn.david.basic.util.PageList;
import cn.david.org.domain.Employee;
import cn.david.org.mapper.EmployeeMapper;
import cn.david.org.query.EmployeeQuery;
import cn.david.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;






    @Override
    public List<Employee> queryAll() {
        return employeeMapper.loadAll();
    }

    @Override
    public void add(Employee employee) {
        employeeMapper.save(employee);

    }

    @Override
    public void update(Employee employee) {
        employeeMapper.update(employee);

    }

    @Override
    public void delete(Long id) {
        employeeMapper.remove(id);

    }

    @Override
    public Employee queryById(Long id) {
        return employeeMapper.loadById(id);
    }

    @Override
    public PageList<Employee> queryPage(EmployeeQuery query) {
        Integer total = employeeMapper.queryCount(query);
        List<Employee> data = employeeMapper.queryData(query);
        return new PageList<Employee>(total,data);
    }


}
